package com.atguigu.ssyx.home.service.impl;

import com.atguigu.ssyx.client.product.ProductFeignClient;
import com.atguigu.ssyx.home.service.HomeService;
import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.search.SkuFeignClient;
import com.atguigu.ssyx.user.UserFeignClient;
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * ClassName: HomeServiceImpl
 * Package: com.atguigu.ssyx.home.service.impl
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-02
 * Time: 23:22
 */

@Service
public class HomeServiceImpl implements HomeService {
    //这个模块这么多远程调用 为什么不直接连接数据库查

    @Autowired
    private UserFeignClient userFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;

    @Autowired
    private SkuFeignClient skuFeignClient;

    //获取首页数据
    @Override
    public Map<String, Object> homeData(Long userId) {
        Map<String,Object> result = new HashMap<>();
        //1.根据userId 获取当前登录的提货地址
        //远程调用service-user中的接口
        //查询shequ-user 中 userDelivery表 通过userId 查到对应的 leaderId 再用leaderId查团长信息
        LeaderAddressVo leaderAddressVo =
                userFeignClient.getUserAddressByUserId(userId);
        result.put("leaderAddressVo",leaderAddressVo);

        //2 获取分类信息
        //远程调用service-product
        List<Category> allCategoryList = productFeignClient.findAllCategoryList();
        result.put("categoryList",allCategoryList);

        //3 获取新人专享商品
        //远程调用service-product
        List<SkuInfo> newPersonSkuInfoList = productFeignClient.findNewPersonSkuInfoList();
        result.put("newPersonSkuInfoList",newPersonSkuInfoList);

        //4 获取爆款产品
        //远程调用service-search
        //有一个字段 score评分降序排序
        List<SkuEs> hotSkuList = skuFeignClient.findHotSkuList();
        result.put("hotSkuList",hotSkuList);
        //5 封装获取的数据到map集合中
        return result;

    }
}
